<?php
/*
 *后台首页
 */
namespace App\Http\Controllers\Admin;
//引入controller控制器
use App\Http\Controllers\OwnController;
//引入请求类
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Gregwar\Captcha\CaptchaBuilder;//引入验证码类
use Illuminate\Support\Facades\Session;//引入session文件
use Cookie;//使用cookie类
Class AdminController extends OwnController
{
	/*
	*后台首页
	*/
	public function index()
	{
		return view('admin.index');
	}

	/*
	*商户审核列表
	*/
	public function merch_show()
	{
		$data = DB::select('select * from manage_merch m INNER JOIN store_type s on m.store_id = s.store_id INNER JOIN `index` on m.index_id = `index`.index_id where is_show = 0');
		return view('admin.merch_show',['data'=>$data]);
	}

	/*
	*商户审核
	*/
	public function merch_audit()
	{
		$arr_id = Input::get();
		$id = $arr_id['id'];
		$res = DB::table('manage_merch')->where('merch_id', $id)->update(['is_show' => 1]);
        if ($res) 
        {
        	 echo "<script>alert('审核通过');location.href='/admin/merch_show';</script>";
        }
       
	}

	/*
	*商户删除
	*/
	public function merch_del()
	{
		$arr_id = Input::get();
		$id = $arr_id['id'];
		$res = DB::table('manage_merch')->where('merch_id',$id)->delete();
	 	if ($res) 
        {
        	 echo "<script>alert('审核通过');location.href='/admin/merch_show';</script>";
        }
	}

	/*
	*商户已审核列表
	*/
	public function merch_list()
	{
		$data = DB::select('select * from manage_merch m INNER JOIN store_type s on m.store_id = s.store_id INNER JOIN `index` on m.index_id = `index`.index_id where is_show = 1');
		return view('admin.merch_list',['data'=>$data]);
	}

	/*
	*商户类型
	*/
	public function store_type()
	{
		return view("admin.store_type");
	}

	/*
	*执行商户类型添加
	*/
	public function store_type_exec()
	{
		$arr_id = Input::all();
		$store_name = $arr_id['store_name'];
		$res = DB::insert("INSERT INTO store_type VALUES(NULL,'$store_name')");
		if ($res) 
        {
        	 echo "<script>alert('添加成功');location.href='/admin/store_type';</script>";
        }
	}
}	